package cn.funeralobjects.aoss.web.api;

import cn.funeralobjects.aoss.enums.BucketAction;
import cn.funeralobjects.aoss.web.model.VBucket;
import cn.funeralobjects.aoss.web.model.VBucketStsAccessKey;
import cn.funeralobjects.common.web.api.RestCodeApi;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.SimplifiedObjectMeta;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * RestApi of Bucket
 *
 * @author FuneralObjects
 * Create date: 2020/6/1 2:56 PM
 */
public interface BucketApi extends RestCodeApi<VBucket, Integer> {

    /**
     * 根据prodResCode进行同步Bucket
     *
     * @param prodResCode prodResCode
     * @return 同步结果
     */
    @PutMapping("/prod-res-code-{prodResCode}/buckets")
    Mono<List<VBucket>> syncBucket(@PathVariable String prodResCode);

    @GetMapping("/{id}/name")
    Mono<String> getBucketName(@PathVariable Integer id);

    @PutMapping("/{id}/ram-role")
    Mono<Void> bindRamRole(@PathVariable Integer id, @RequestParam("ram-role-code") String ramRoleCode);

    @PostMapping("/{id}/sts")
    Mono<VBucketStsAccessKey> createStsAccess(@PathVariable Integer id,
                                              @RequestParam("sts-prod-res-id") Integer stsProdResId,
                                              @RequestParam("action") BucketAction action,
                                              @RequestParam("path") String path,
                                              @RequestParam(value = "duration", required = false) Long duration);

    @GetMapping("/{id}/object/simplified-meta")
    Mono<SimplifiedObjectMeta> getSimplifiedObjectMeta(@PathVariable Integer id,
                                                       @RequestParam("object-path") String objectPath);

    @GetMapping("/{id}/object/head-meta")
    Mono<ObjectMetadata> headObjectMeta(@PathVariable Integer id, @RequestParam("object-path") String objectPath);
}
